<template>
  <div>
    <el-row>
      <el-button type="primary" style="margin-bottom: 12px" @click="handleAdd">添加</el-button>
      <el-table :data="tableData" class="table-body" :header-cell-style="{background:'#F4F6F9',color:'#1D2129'}" row-key="moduleId" :tree-props="{children: 'childList'}">
        <el-table-column prop="moduleName" label="名称"></el-table-column>
        <el-table-column prop="updateDate" label="更新时间" width="150"></el-table-column>
        <el-table-column label="操作" width="100" fixed="right">
          <template slot-scope="scope">
<!--            <el-button type="text" :disabled="!scope.row.editFlag" @click="handleEdit(scope.row.moduleId)">编辑</el-button>-->
            <el-button type="text" @click="handleEdit(scope.row.moduleId)">编辑</el-button>
            <el-button type="text" @click="handleDelete(scope.row.moduleId)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-row>
    <Add ref="add" :tableData="tableData" @getParentTableData="getParentTableData"/>
    <Detail ref="detail" :tableData="tableData" @getParentTableData="getParentTableData" />
  </div>
</template>

<script>
import Add from "./Add.vue";
import Detail from "./Detail.vue";
import { deleteModuleApi } from "@/api/modules/modules.api";

export default {
  components: { Add,Detail },
  props: ['tableData','count'],
  data() {
    return {
      visible: false,
      id: '',
      page: {
        pageNum: 1,
        pageSize: 10
      }
    };
  },
  methods: {
    handleCheck(id) {
      this.$refs.detail.init(id)
    },
    async handleDelete(id){
      await deleteModuleApi(id)
      this.$message({
        message: '成功',
        type: 'success'
      });
      this.$emit('getTableData',this.page)
    },
    handleAdd() {
      this.$refs.add.init()
    },
    getParentTableData(){
      this.$emit('getTableData',this.page)
    },
    handleEdit(id){
      this.$refs.detail.init(id)
    }
  }
}
</script>
